<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License 
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: TranslateArray.php 262 2011-07-23 15:51:14Z beimuaihui $
 */


Zend_Loader::loadClass("Baogg_Db_Table");

class TranslateArray  extends Baogg_Db_Table {
	/**
	 * The default table name 
	 */
	protected $_name;
	protected $_db ;
	protected $_primary;
	 
	
	function __construct() {
		$this->_name =   'translate_array';
		$this->_myPrimary=$this->_primary= "translate_array_id";
		
		parent::__construct();
		
	}
	
	
    

    /*
     *   get  data list
     */
    function getListCount($where=array()) {
        

        
        $select=$this->_db->select()->from(array("a"=>"translate_var"),"*")
                                    ->join(array("b"=>$this->_name ),"a.translate_var_id=b.translate_var_id",array("b.content"))
                                    ->joinLeft(array("c"=> "menu"),'a.menu_id=c.menu_id',array("c.menu_name"));       
            
        foreach((array)$where as $k=>$v){
            if(in_array($k,array("translate_var_id","menu_id"))){  //ambigiourouse column
                $k="a.".$k;
            }
            
            if(is_int($v) || is_float($v)){
               $select->where("$k =  ?",$v ) ; 
            }else{
               $select->where("$k like  ?",$v ) ;
            }
        }
       
      
     // echo $select;exit;        
       $rs=$this->_db->fetchOne($select);
      // $rs[0]['sub_table']='gg';
       
       return $rs;  
    }
    
	

	function getSame($arr) {	
		$ret=array();
        
		if(isset($arr[$this->_myPrimary])){		
	        $sql = $this->_db->quoteInto('SELECT * FROM ' . $this->_name . ' WHERE '.$this->_myPrimary.' = ? ', $arr[$this->_myPrimary]);
		}else if(isset($arr['translate_var_id']) && isset($arr['language_id'])  ){
			$sql = "SELECT {$this->_myPrimary} FROM {$this->_name} WHERE translate_var_id ='{$arr['translate_var_id']}' and language_id ='{$arr['language_id']}' ";
		}else{
			return array();
		}
		//echo $sql;exit();
		$rs = $this->_db->query($sql)->fetchAll();
		foreach((array)$rs as $v)
		{
		    $ret[]=$v[$this->_myPrimary];
		}
		return $ret; 	
	
	}
	
    
	
}
